<?php

/*============================================
Classe McsParameters
============================================*/

class McsParameters extends ModelObject{

	protected static $cached_object_list= array();
	protected $PARAMETER_NAME;
	protected $PARACOM;
	protected $PARACOM_LONG;
	protected $MONITORING_STATUS;
	protected $SEVERITY;
	protected $PARAMETER_KIND;
	protected $COM_OPE;
	protected $PARAMETER_UNIT;
	protected $PARAMETER_TYPE;
	protected $PARAMETER_ACCURACY;
	protected $DEVICE_NAME;
	protected $LOWER_THRESHOLD;
	protected $UPPER_THRESHOLD;
	protected $MIN_VAL;
	protected $MAX_VAL;
	protected $EXPECTED_VALUE;
	protected $TOLERANCE;
	protected $PARAMETER_FORMAT;
	protected $FORMAT_EXT;
	protected $EVENT_FORMAT;
	protected $MEAS_NAME;
	protected $TO_TRANSMIT;
	protected $TO_REPORT;
	protected $INTERPRETATION;
	protected $FORMULA;
	protected $ITEM_IND;
	protected $FIRST_BIT;
	protected $NB_BITS;
	protected $VALUE_0;
	protected $VALUE_1;
	protected $VALUE_2;
	protected $VALUE_3;

	protected function __construct( $PARAMETER_NAME,$PARACOM,$PARACOM_LONG,$MONITORING_STATUS,$SEVERITY,$PARAMETER_KIND,$COM_OPE,$PARAMETER_UNIT,$PARAMETER_TYPE,$PARAMETER_ACCURACY,$DEVICE_NAME,$LOWER_THRESHOLD,$UPPER_THRESHOLD,$MIN_VAL,$MAX_VAL,$EXPECTED_VALUE,$TOLERANCE,$PARAMETER_FORMAT,$FORMAT_EXT,$EVENT_FORMAT,$MEAS_NAME,$TO_TRANSMIT,$TO_REPORT,$INTERPRETATION,$FORMULA,$ITEM_IND,$FIRST_BIT,$NB_BITS,$VALUE_0,$VALUE_1,$VALUE_2,$VALUE_3){
		try{
			
			$this->PARAMETER_NAME = $PARAMETER_NAME;
			$this->PARACOM = $PARACOM;
			$this->PARACOM_LONG = $PARACOM_LONG;
			$this->MONITORING_STATUS = $MONITORING_STATUS;
			$this->SEVERITY = $SEVERITY;
			$this->PARAMETER_KIND = $PARAMETER_KIND;
			$this->COM_OPE = $COM_OPE;
			$this->PARAMETER_UNIT = $PARAMETER_UNIT;
			$this->PARAMETER_TYPE = $PARAMETER_TYPE;
			$this->PARAMETER_ACCURACY = $PARAMETER_ACCURACY;
			$this->DEVICE_NAME = $DEVICE_NAME;
			$this->LOWER_THRESHOLD = $LOWER_THRESHOLD;
			$this->UPPER_THRESHOLD = $UPPER_THRESHOLD;
			$this->MIN_VAL = $MIN_VAL;
			$this->MAX_VAL = $MAX_VAL;
			$this->EXPECTED_VALUE = $EXPECTED_VALUE;
			$this->TOLERANCE = $TOLERANCE;
			$this->PARAMETER_FORMAT = $PARAMETER_FORMAT;
			$this->FORMAT_EXT = $FORMAT_EXT;
			$this->EVENT_FORMAT = $EVENT_FORMAT;
			$this->MEAS_NAME = $MEAS_NAME;
			$this->TO_TRANSMIT = $TO_TRANSMIT;
			$this->TO_REPORT = $TO_REPORT;
			$this->INTERPRETATION = $INTERPRETATION;
			$this->FORMULA = $FORMULA;
			$this->ITEM_IND = $ITEM_IND;
			$this->FIRST_BIT = $FIRST_BIT;
			$this->NB_BITS = $NB_BITS;
			$this->VALUE_0 = $VALUE_0;
			$this->VALUE_1 = $VALUE_1;
			$this->VALUE_2 = $VALUE_2;
			$this->VALUE_3 = $VALUE_3;
		}
		catch(Excpetion $e){
			throw new Exception("La construction de l'objet de type get_class($this) a échouée",0,$e);
		}
	}

	public function getPARAMETERNAME(){
		return $this->PARAMETER_NAME;
	}

	public function getPARACOM(){
		return $this->PARACOM;
	}

	public function getPARACOMLONG(){
		return $this->PARACOM_LONG;
	}

	public function getMONITORINGSTATUS(){
		return $this->MONITORING_STATUS;
	}

	public function getSEVERITY(){
		return $this->SEVERITY;
	}

	public function getPARAMETERKIND(){
		return $this->PARAMETER_KIND;
	}

	public function getCOMOPE(){
		return $this->COM_OPE;
	}

	public function getPARAMETERUNIT(){
		return $this->PARAMETER_UNIT;
	}

	public function getPARAMETERTYPE(){
		return $this->PARAMETER_TYPE;
	}

	public function getPARAMETERACCURACY(){
		return $this->PARAMETER_ACCURACY;
	}

	public function getDEVICENAME(){
		return DEVICENAME::get($this->DEVICE_NAME);
	}

	public function getLOWERTHRESHOLD(){
		return $this->LOWER_THRESHOLD;
	}

	public function getUPPERTHRESHOLD(){
		return $this->UPPER_THRESHOLD;
	}

	public function getMINVAL(){
		return $this->MIN_VAL;
	}

	public function getMAXVAL(){
		return $this->MAX_VAL;
	}

	public function getEXPECTEDVALUE(){
		return $this->EXPECTED_VALUE;
	}

	public function getTOLERANCE(){
		return $this->TOLERANCE;
	}

	public function getPARAMETERFORMAT(){
		return $this->PARAMETER_FORMAT;
	}

	public function getFORMATEXT(){
		return $this->FORMAT_EXT;
	}

	public function getEVENTFORMAT(){
		return $this->EVENT_FORMAT;
	}

	public function getMEASNAME(){
		return $this->MEAS_NAME;
	}

	public function getTOTRANSMIT(){
		return $this->TO_TRANSMIT;
	}

	public function getTOREPORT(){
		return $this->TO_REPORT;
	}

	public function getINTERPRETATION(){
		return $this->INTERPRETATION;
	}

	public function getFORMULA(){
		return $this->FORMULA;
	}

	public function getITEMIND(){
		return $this->ITEM_IND;
	}

	public function getFIRSTBIT(){
		return $this->FIRST_BIT;
	}

	public function getNBBITS(){
		return $this->NB_BITS;
	}

	public function getVALUE0(){
		return $this->VALUE_0;
	}

	public function getVALUE1(){
		return $this->VALUE_1;
	}

	public function getVALUE2(){
		return $this->VALUE_2;
	}

	public function getVALUE3(){
		return $this->VALUE_3;
	}

	public function setPARACOM( $PARACOM){
		try{
			$temp = $this->PARACOM;
			if($this->PARACOM !== $PARACOM){
				$this->PARACOM = $PARACOM;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->PARACOM = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setPARACOM() a échouée",0,$e);
		}
	}

	public function setPARACOMLONG( $PARACOM_LONG){
		try{
			$temp = $this->PARACOM_LONG;
			if($this->PARACOM_LONG !== $PARACOM_LONG){
				$this->PARACOM_LONG = $PARACOM_LONG;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->PARACOM_LONG = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setPARACOMLONG() a échouée",0,$e);
		}
	}

	public function setMONITORINGSTATUS( $MONITORING_STATUS){
		try{
			$temp = $this->MONITORING_STATUS;
			if($this->MONITORING_STATUS !== $MONITORING_STATUS){
				$this->MONITORING_STATUS = $MONITORING_STATUS;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->MONITORING_STATUS = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setMONITORINGSTATUS() a échouée",0,$e);
		}
	}

	public function setSEVERITY( $SEVERITY){
		try{
			$temp = $this->SEVERITY;
			if($this->SEVERITY !== $SEVERITY){
				$this->SEVERITY = $SEVERITY;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->SEVERITY = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setSEVERITY() a échouée",0,$e);
		}
	}

	public function setPARAMETERKIND( $PARAMETER_KIND){
		try{
			$temp = $this->PARAMETER_KIND;
			if($this->PARAMETER_KIND !== $PARAMETER_KIND){
				$this->PARAMETER_KIND = $PARAMETER_KIND;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->PARAMETER_KIND = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setPARAMETERKIND() a échouée",0,$e);
		}
	}

	public function setCOMOPE( $COM_OPE){
		try{
			$temp = $this->COM_OPE;
			if($this->COM_OPE !== $COM_OPE){
				$this->COM_OPE = $COM_OPE;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->COM_OPE = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setCOMOPE() a échouée",0,$e);
		}
	}

	public function setPARAMETERUNIT( $PARAMETER_UNIT){
		try{
			$temp = $this->PARAMETER_UNIT;
			if($this->PARAMETER_UNIT !== $PARAMETER_UNIT){
				$this->PARAMETER_UNIT = $PARAMETER_UNIT;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->PARAMETER_UNIT = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setPARAMETERUNIT() a échouée",0,$e);
		}
	}

	public function setPARAMETERTYPE( $PARAMETER_TYPE){
		try{
			$temp = $this->PARAMETER_TYPE;
			if($this->PARAMETER_TYPE !== $PARAMETER_TYPE){
				$this->PARAMETER_TYPE = $PARAMETER_TYPE;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->PARAMETER_TYPE = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setPARAMETERTYPE() a échouée",0,$e);
		}
	}

	public function setPARAMETERACCURACY( $PARAMETER_ACCURACY){
		try{
			$temp = $this->PARAMETER_ACCURACY;
			if($this->PARAMETER_ACCURACY !== $PARAMETER_ACCURACY){
				$this->PARAMETER_ACCURACY = $PARAMETER_ACCURACY;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->PARAMETER_ACCURACY = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setPARAMETERACCURACY() a échouée",0,$e);
		}
	}

	public function setDEVICENAME( $DEVICE_NAME){
		try{
			$temp = $this->DEVICE_NAME;
			if(is_null($DEVICE_NAME)){
				throw new Exception("Le paramètre \$dEVICE_NAME de type get_class($dEVICE_NAME) est null alors que la colonne dans la base est marquée comme NOT NULL");
			}
			else if(!($DEVICE_NAME instanceof DEVICENAME) || is_null($DEVICE_NAME->getId())){
				throw new Exception("Le paramètre \$dEVICE_NAME de type get_class($dEVICE_NAME) n'est pas du bon type ou n'est pas présent dans la base");
			}
			else {
				if($this->DEVICE_NAME !== $DEVICE_NAME->getId()){
					$this->DEVICE_NAME = $DEVICE_NAME->getId();
					$this->update();
				}
			}
		}
		catch(Exception $e){
			$this->DEVICE_NAME = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setDEVICENAME() a échouée",0,$e);
		}
	}

	public function setLOWERTHRESHOLD( $LOWER_THRESHOLD){
		try{
			$temp = $this->LOWER_THRESHOLD;
			if($this->LOWER_THRESHOLD !== $LOWER_THRESHOLD){
				$this->LOWER_THRESHOLD = $LOWER_THRESHOLD;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->LOWER_THRESHOLD = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setLOWERTHRESHOLD() a échouée",0,$e);
		}
	}

	public function setUPPERTHRESHOLD( $UPPER_THRESHOLD){
		try{
			$temp = $this->UPPER_THRESHOLD;
			if($this->UPPER_THRESHOLD !== $UPPER_THRESHOLD){
				$this->UPPER_THRESHOLD = $UPPER_THRESHOLD;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->UPPER_THRESHOLD = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setUPPERTHRESHOLD() a échouée",0,$e);
		}
	}

	public function setMINVAL( $MIN_VAL){
		try{
			$temp = $this->MIN_VAL;
			if($this->MIN_VAL !== $MIN_VAL){
				$this->MIN_VAL = $MIN_VAL;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->MIN_VAL = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setMINVAL() a échouée",0,$e);
		}
	}

	public function setMAXVAL( $MAX_VAL){
		try{
			$temp = $this->MAX_VAL;
			if($this->MAX_VAL !== $MAX_VAL){
				$this->MAX_VAL = $MAX_VAL;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->MAX_VAL = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setMAXVAL() a échouée",0,$e);
		}
	}

	public function setEXPECTEDVALUE( $EXPECTED_VALUE){
		try{
			$temp = $this->EXPECTED_VALUE;
			if($this->EXPECTED_VALUE !== $EXPECTED_VALUE){
				$this->EXPECTED_VALUE = $EXPECTED_VALUE;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->EXPECTED_VALUE = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setEXPECTEDVALUE() a échouée",0,$e);
		}
	}

	public function setTOLERANCE( $TOLERANCE){
		try{
			$temp = $this->TOLERANCE;
			if($this->TOLERANCE !== $TOLERANCE){
				$this->TOLERANCE = $TOLERANCE;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->TOLERANCE = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setTOLERANCE() a échouée",0,$e);
		}
	}

	public function setPARAMETERFORMAT( $PARAMETER_FORMAT){
		try{
			$temp = $this->PARAMETER_FORMAT;
			if($this->PARAMETER_FORMAT !== $PARAMETER_FORMAT){
				$this->PARAMETER_FORMAT = $PARAMETER_FORMAT;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->PARAMETER_FORMAT = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setPARAMETERFORMAT() a échouée",0,$e);
		}
	}

	public function setFORMATEXT( $FORMAT_EXT){
		try{
			$temp = $this->FORMAT_EXT;
			if($this->FORMAT_EXT !== $FORMAT_EXT){
				$this->FORMAT_EXT = $FORMAT_EXT;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->FORMAT_EXT = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setFORMATEXT() a échouée",0,$e);
		}
	}

	public function setEVENTFORMAT( $EVENT_FORMAT){
		try{
			$temp = $this->EVENT_FORMAT;
			if($this->EVENT_FORMAT !== $EVENT_FORMAT){
				$this->EVENT_FORMAT = $EVENT_FORMAT;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->EVENT_FORMAT = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setEVENTFORMAT() a échouée",0,$e);
		}
	}

	public function setMEASNAME( $MEAS_NAME){
		try{
			$temp = $this->MEAS_NAME;
			if($this->MEAS_NAME !== $MEAS_NAME){
				$this->MEAS_NAME = $MEAS_NAME;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->MEAS_NAME = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setMEASNAME() a échouée",0,$e);
		}
	}

	public function setTOTRANSMIT( $TO_TRANSMIT){
		try{
			$temp = $this->TO_TRANSMIT;
			if($this->TO_TRANSMIT !== $TO_TRANSMIT){
				$this->TO_TRANSMIT = $TO_TRANSMIT;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->TO_TRANSMIT = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setTOTRANSMIT() a échouée",0,$e);
		}
	}

	public function setTOREPORT( $TO_REPORT){
		try{
			$temp = $this->TO_REPORT;
			if($this->TO_REPORT !== $TO_REPORT){
				$this->TO_REPORT = $TO_REPORT;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->TO_REPORT = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setTOREPORT() a échouée",0,$e);
		}
	}

	public function setINTERPRETATION( $INTERPRETATION){
		try{
			$temp = $this->INTERPRETATION;
			if($this->INTERPRETATION !== $INTERPRETATION){
				$this->INTERPRETATION = $INTERPRETATION;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->INTERPRETATION = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setINTERPRETATION() a échouée",0,$e);
		}
	}

	public function setFORMULA( $FORMULA){
		try{
			$temp = $this->FORMULA;
			if($this->FORMULA !== $FORMULA){
				$this->FORMULA = $FORMULA;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->FORMULA = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setFORMULA() a échouée",0,$e);
		}
	}

	public function setITEMIND( $ITEM_IND){
		try{
			$temp = $this->ITEM_IND;
			if($this->ITEM_IND !== $ITEM_IND){
				$this->ITEM_IND = $ITEM_IND;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->ITEM_IND = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setITEMIND() a échouée",0,$e);
		}
	}

	public function setFIRSTBIT( $FIRST_BIT){
		try{
			$temp = $this->FIRST_BIT;
			if($this->FIRST_BIT !== $FIRST_BIT){
				$this->FIRST_BIT = $FIRST_BIT;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->FIRST_BIT = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setFIRSTBIT() a échouée",0,$e);
		}
	}

	public function setNBBITS( $NB_BITS){
		try{
			$temp = $this->NB_BITS;
			if($this->NB_BITS !== $NB_BITS){
				$this->NB_BITS = $NB_BITS;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->NB_BITS = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setNBBITS() a échouée",0,$e);
		}
	}

	public function setVALUE0( $VALUE_0){
		try{
			$temp = $this->VALUE_0;
			if($this->VALUE_0 !== $VALUE_0){
				$this->VALUE_0 = $VALUE_0;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->VALUE_0 = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setVALUE0() a échouée",0,$e);
		}
	}

	public function setVALUE1( $VALUE_1){
		try{
			$temp = $this->VALUE_1;
			if($this->VALUE_1 !== $VALUE_1){
				$this->VALUE_1 = $VALUE_1;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->VALUE_1 = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setVALUE1() a échouée",0,$e);
		}
	}

	public function setVALUE2( $VALUE_2){
		try{
			$temp = $this->VALUE_2;
			if($this->VALUE_2 !== $VALUE_2){
				$this->VALUE_2 = $VALUE_2;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->VALUE_2 = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setVALUE2() a échouée",0,$e);
		}
	}

	public function setVALUE3( $VALUE_3){
		try{
			$temp = $this->VALUE_3;
			if($this->VALUE_3 !== $VALUE_3){
				$this->VALUE_3 = $VALUE_3;
				$this->update();
			}
		}
		catch(Exception $e){
			$this->VALUE_3 = $temp;
			throw new Exception("La modification de l'attribut par l'appel à la méthode setVALUE3() a échouée",0,$e);
		}
	}

	public static function create( $PARAMETER_NAME,$PARACOM,$PARACOM_LONG,$MONITORING_STATUS,$SEVERITY,$PARAMETER_KIND,$COM_OPE,$PARAMETER_UNIT,$PARAMETER_TYPE,$PARAMETER_ACCURACY,$DEVICE_NAME,$LOWER_THRESHOLD,$UPPER_THRESHOLD,$MIN_VAL,$MAX_VAL,$EXPECTED_VALUE,$TOLERANCE,$PARAMETER_FORMAT,$FORMAT_EXT,$EVENT_FORMAT,$MEAS_NAME,$TO_TRANSMIT,$TO_REPORT,$INTERPRETATION,$FORMULA,$ITEM_IND,$FIRST_BIT,$NB_BITS,$VALUE_0,$VALUE_1,$VALUE_2,$VALUE_3){
		try{
			$mcsParameters = new McsParameters($PARAMETER_NAME, $PARACOM, $PARACOM_LONG, $MONITORING_STATUS, $SEVERITY, $PARAMETER_KIND, $COM_OPE, $PARAMETER_UNIT, $PARAMETER_TYPE, $PARAMETER_ACCURACY, $DEVICE_NAME, $LOWER_THRESHOLD, $UPPER_THRESHOLD, $MIN_VAL, $MAX_VAL, $EXPECTED_VALUE, $TOLERANCE, $PARAMETER_FORMAT, $FORMAT_EXT, $EVENT_FORMAT, $MEAS_NAME, $TO_TRANSMIT, $TO_REPORT, $INTERPRETATION, $FORMULA, $ITEM_IND, $FIRST_BIT, $NB_BITS, $VALUE_0, $VALUE_1, $VALUE_2, $VALUE_3);
			$mcsParameters->insert();
			McsParameters::cacheObject($mcsParameters);
			return $mcsParameters;
		}
		catch(Excpetion $e){
			throw new Exception("La création de l'objet de type McsParameters a échouée",0,$e);
		}
	}

	public static function get( $PARAMETER_NAME){
		$dbh = SingletonPDO::getInstance();
		try{
			if(is_null($PARAMETER_NAME) || $PARAMETER_NAME === "") {
				return null;
			}
			if(McsParameters::existsInCache($PARAMETER_NAME)) {
				return McsParameters::getFromCache($PARAMETER_NAME);
			}
			$dbh->beginTransaction();
			$sql= 'SELECT * FROM `mcs_parameters` WHERE `PARAMETER_NAME` = :id';
			$stmt = $dbh->prepare($sql);
			$stmt->execute(array(':id'=>$PARAMETER_NAME));
			if ($row = $stmt->fetch()){
				$mcsParameters = new McsParameters( $row['PARAMETER_NAME'],$row['PARACOM'],$row['PARACOM_LONG'],$row['MONITORING_STATUS'],$row['SEVERITY'],$row['PARAMETER_KIND'],$row['COM_OPE'],$row['PARAMETER_UNIT'],$row['PARAMETER_TYPE'],$row['PARAMETER_ACCURACY'],$row['DEVICE_NAME'],$row['LOWER_THRESHOLD'],$row['UPPER_THRESHOLD'],$row['MIN_VAL'],$row['MAX_VAL'],$row['EXPECTED_VALUE'],$row['TOLERANCE'],$row['PARAMETER_FORMAT'],$row['FORMAT_EXT'],$row['EVENT_FORMAT'],$row['MEAS_NAME'],$row['TO_TRANSMIT'],$row['TO_REPORT'],$row['INTERPRETATION'],$row['FORMULA'],$row['ITEM_IND'],$row['FIRST_BIT'],$row['NB_BITS'],$row['VALUE_0'],$row['VALUE_1'],$row['VALUE_2'],$row['VALUE_3']);
				$mcsParameters->id =  $row['PARAMETER_NAME'];
				$dbh->commit();
				McsParameters::cacheObject($mcsParameters);
				return $mcsParameters;
			}
			else {
				$dbh->commit();
				return null;
			}
		}
		catch(Exception $e) {
			$dbh->rollBack();
			throw new Exception("La récupération de l'objet ayant l'id ". $PARAMETER_NAME . " a échouée",0,$e);
		}
	}

	protected function update(){
		$dbh = SingletonPDO::getInstance();
		try{
			$dbh->beginTransaction();
			if (is_null($this->id)) {
				throw new Exception("Cet objet de type ".get_class($this)." n'a pas encore été enregistré dans la base");
			}
			$sql='UPDATE `mcs_parameters` SET `PARACOM` = :PARACOM, `PARACOM_LONG` = :PARACOM_LONG, `MONITORING_STATUS` = :MONITORING_STATUS, `SEVERITY` = :SEVERITY, `PARAMETER_KIND` = :PARAMETER_KIND, `COM_OPE` = :COM_OPE, `PARAMETER_UNIT` = :PARAMETER_UNIT, `PARAMETER_TYPE` = :PARAMETER_TYPE, `PARAMETER_ACCURACY` = :PARAMETER_ACCURACY, `DEVICE_NAME` = :DEVICE_NAME, `LOWER_THRESHOLD` = :LOWER_THRESHOLD, `UPPER_THRESHOLD` = :UPPER_THRESHOLD, `MIN_VAL` = :MIN_VAL, `MAX_VAL` = :MAX_VAL, `EXPECTED_VALUE` = :EXPECTED_VALUE, `TOLERANCE` = :TOLERANCE, `PARAMETER_FORMAT` = :PARAMETER_FORMAT, `FORMAT_EXT` = :FORMAT_EXT, `EVENT_FORMAT` = :EVENT_FORMAT, `MEAS_NAME` = :MEAS_NAME, `TO_TRANSMIT` = :TO_TRANSMIT, `TO_REPORT` = :TO_REPORT, `INTERPRETATION` = :INTERPRETATION, `FORMULA` = :FORMULA, `ITEM_IND` = :ITEM_IND, `FIRST_BIT` = :FIRST_BIT, `NB_BITS` = :NB_BITS, `VALUE_0` = :VALUE_0, `VALUE_1` = :VALUE_1, `VALUE_2` = :VALUE_2, `VALUE_3` = :VALUE_3 WHERE `PARAMETER_NAME` = :id';
			$stmt = $dbh->prepare($sql);
			$stmt->execute(array(':PARACOM'=>$this->PARACOM, ':PARACOM_LONG'=>$this->PARACOM_LONG, ':MONITORING_STATUS'=>$this->MONITORING_STATUS, ':SEVERITY'=>$this->SEVERITY, ':PARAMETER_KIND'=>$this->PARAMETER_KIND, ':COM_OPE'=>$this->COM_OPE, ':PARAMETER_UNIT'=>$this->PARAMETER_UNIT, ':PARAMETER_TYPE'=>$this->PARAMETER_TYPE, ':PARAMETER_ACCURACY'=>$this->PARAMETER_ACCURACY, ':DEVICE_NAME'=>$this->DEVICE_NAME, ':LOWER_THRESHOLD'=>$this->LOWER_THRESHOLD, ':UPPER_THRESHOLD'=>$this->UPPER_THRESHOLD, ':MIN_VAL'=>$this->MIN_VAL, ':MAX_VAL'=>$this->MAX_VAL, ':EXPECTED_VALUE'=>$this->EXPECTED_VALUE, ':TOLERANCE'=>$this->TOLERANCE, ':PARAMETER_FORMAT'=>$this->PARAMETER_FORMAT, ':FORMAT_EXT'=>$this->FORMAT_EXT, ':EVENT_FORMAT'=>$this->EVENT_FORMAT, ':MEAS_NAME'=>$this->MEAS_NAME, ':TO_TRANSMIT'=>$this->TO_TRANSMIT, ':TO_REPORT'=>$this->TO_REPORT, ':INTERPRETATION'=>$this->INTERPRETATION, ':FORMULA'=>$this->FORMULA, ':ITEM_IND'=>$this->ITEM_IND, ':FIRST_BIT'=>$this->FIRST_BIT, ':NB_BITS'=>$this->NB_BITS, ':VALUE_0'=>$this->VALUE_0, ':VALUE_1'=>$this->VALUE_1, ':VALUE_2'=>$this->VALUE_2, ':VALUE_3'=>$this->VALUE_3, ':id'=>$this->id));
			$dbh->commit();
		}
		catch(Exception $e) {
			$dbh->rollBack();
			throw new Exception("La modification de l'objet de type ".get_class($this)." ayant l'id ". $this->id . " a échouée",0,$e);
		}
	}

	public function delete(){
		$dbh = SingletonPDO::getInstance();
		try{
			$dbh->beginTransaction();
			if (is_null($this->id)) {
				throw new Exception("Cet objet de type ".get_class($this)." n'a pas encore été enregistré dans la base");
			}
			$sql = 'DELETE FROM `mcs_parameters` WHERE `PARAMETER_NAME` = :id';
			$stmt = $dbh->prepare($sql);
			$stmt->execute(array(':id'=>$this->id));
			McsParameters::removeObjectFromCache($this->id);
			$this->id = null;
			$dbh->commit();
		}
		catch(Exception $e) {
			$dbh->rollBack();
			throw new Exception("La suppression de l'objet de type ".get_class($this)." ayant l'id ". $this->id. " a échouée",0,$e);
		}
	}

	protected function insert(){
		$dbh = SingletonPDO::getInstance();
		try{
			if (is_null($this->id)) {
				$dbh->beginTransaction();
				$sql='INSERT INTO `mcs_parameters` ( `PARACOM`, `PARACOM_LONG`, `MONITORING_STATUS`, `SEVERITY`, `PARAMETER_KIND`, `COM_OPE`, `PARAMETER_UNIT`, `PARAMETER_TYPE`, `PARAMETER_ACCURACY`, `DEVICE_NAME`, `LOWER_THRESHOLD`, `UPPER_THRESHOLD`, `MIN_VAL`, `MAX_VAL`, `EXPECTED_VALUE`, `TOLERANCE`, `PARAMETER_FORMAT`, `FORMAT_EXT`, `EVENT_FORMAT`, `MEAS_NAME`, `TO_TRANSMIT`, `TO_REPORT`, `INTERPRETATION`, `FORMULA`, `ITEM_IND`, `FIRST_BIT`, `NB_BITS`, `VALUE_0`, `VALUE_1`, `VALUE_2`, `VALUE_3`) VALUES (:PARACOM, :PARACOM_LONG, :MONITORING_STATUS, :SEVERITY, :PARAMETER_KIND, :COM_OPE, :PARAMETER_UNIT, :PARAMETER_TYPE, :PARAMETER_ACCURACY, :DEVICE_NAME, :LOWER_THRESHOLD, :UPPER_THRESHOLD, :MIN_VAL, :MAX_VAL, :EXPECTED_VALUE, :TOLERANCE, :PARAMETER_FORMAT, :FORMAT_EXT, :EVENT_FORMAT, :MEAS_NAME, :TO_TRANSMIT, :TO_REPORT, :INTERPRETATION, :FORMULA, :ITEM_IND, :FIRST_BIT, :NB_BITS, :VALUE_0, :VALUE_1, :VALUE_2, :VALUE_3)';
				$stmt = $dbh->prepare($sql);
				$stmt->execute(array(':PARACOM'=>$this->PARACOM, ':PARACOM_LONG'=>$this->PARACOM_LONG, ':MONITORING_STATUS'=>$this->MONITORING_STATUS, ':SEVERITY'=>$this->SEVERITY, ':PARAMETER_KIND'=>$this->PARAMETER_KIND, ':COM_OPE'=>$this->COM_OPE, ':PARAMETER_UNIT'=>$this->PARAMETER_UNIT, ':PARAMETER_TYPE'=>$this->PARAMETER_TYPE, ':PARAMETER_ACCURACY'=>$this->PARAMETER_ACCURACY, ':DEVICE_NAME'=>$this->DEVICE_NAME, ':LOWER_THRESHOLD'=>$this->LOWER_THRESHOLD, ':UPPER_THRESHOLD'=>$this->UPPER_THRESHOLD, ':MIN_VAL'=>$this->MIN_VAL, ':MAX_VAL'=>$this->MAX_VAL, ':EXPECTED_VALUE'=>$this->EXPECTED_VALUE, ':TOLERANCE'=>$this->TOLERANCE, ':PARAMETER_FORMAT'=>$this->PARAMETER_FORMAT, ':FORMAT_EXT'=>$this->FORMAT_EXT, ':EVENT_FORMAT'=>$this->EVENT_FORMAT, ':MEAS_NAME'=>$this->MEAS_NAME, ':TO_TRANSMIT'=>$this->TO_TRANSMIT, ':TO_REPORT'=>$this->TO_REPORT, ':INTERPRETATION'=>$this->INTERPRETATION, ':FORMULA'=>$this->FORMULA, ':ITEM_IND'=>$this->ITEM_IND, ':FIRST_BIT'=>$this->FIRST_BIT, ':NB_BITS'=>$this->NB_BITS, ':VALUE_0'=>$this->VALUE_0, ':VALUE_1'=>$this->VALUE_1, ':VALUE_2'=>$this->VALUE_2, ':VALUE_3'=>$this->VALUE_3));
				$this->id = $dbh->lastInsertId();
				$dbh->commit();
			}
		}
		catch(Exception $e) {
			$dbh->rollBack();
			throw new Exception("L'insertion de l'objet de type ".get_class($this)." a échouée",0,$e);
		}
	}

	public static function getAll( $search_params = array(),$options = array()){
		$dbh = SingletonPDO::getInstance();
		try{
			$dbh->beginTransaction();
			$objs = array();
			$sql = 'SELECT * FROM `mcs_parameters`';
			$sql .= self::generateWhereClause($search_params);
			$sql .= self::generateOptionClause($options);
			$stmt = $dbh->prepare($sql);
			$array = array();
			$cpt = 0;
			foreach($search_params as $ind => $search_param){
				//ajouter un parametre au tableau
				if($search_param['operator'] === 'BETWEEN' && is_array($search_param['value']) && count($search_param['value']) == 2 ){
					$array[':'.$search_param['field'].$cpt.'_0'] = $search_param['value'][0];
					$array[':'.$search_param['field'].$cpt.'_1'] = $search_param['value'][1];
				}
				else if($search_param['operator'] === 'IN' && is_array($search_param['value']) && count($search_param['value']) > 0){
					$i = 0;
					foreach($search_param['value'] as $key => $val){
						$array[':'.$search_param['field'].$cpt.'_'.$i] = $val;
						$i++;
					}
					if($i == 0){
						throw new Exception("L'opérateur IN doit comporter au moins une valeur");
					}
				}
				else if ($search_param['operator'] === 'IS NULL' || $search_param['operator'] === 'IS NOT NULL'){
					continue;
				}
				else{
					$array[':'.$search_param['field'].$cpt] = $search_param['value'];
				}
				$cpt++;
			}
			$stmt->execute($array);
			while ($row = $stmt->fetch()) {
				$obj = null;
				if(McsParameters::existsInCache($row['PARAMETER_NAME'])){
					$obj = McsParameters::getFromCache($row['PARAMETER_NAME']);
				}
				else{
					$obj = new McsParameters( $row['PARAMETER_NAME'],$row['PARACOM'],$row['PARACOM_LONG'],$row['MONITORING_STATUS'],$row['SEVERITY'],$row['PARAMETER_KIND'],$row['COM_OPE'],$row['PARAMETER_UNIT'],$row['PARAMETER_TYPE'],$row['PARAMETER_ACCURACY'],$row['DEVICE_NAME'],$row['LOWER_THRESHOLD'],$row['UPPER_THRESHOLD'],$row['MIN_VAL'],$row['MAX_VAL'],$row['EXPECTED_VALUE'],$row['TOLERANCE'],$row['PARAMETER_FORMAT'],$row['FORMAT_EXT'],$row['EVENT_FORMAT'],$row['MEAS_NAME'],$row['TO_TRANSMIT'],$row['TO_REPORT'],$row['INTERPRETATION'],$row['FORMULA'],$row['ITEM_IND'],$row['FIRST_BIT'],$row['NB_BITS'],$row['VALUE_0'],$row['VALUE_1'],$row['VALUE_2'],$row['VALUE_3']);
				}
				if(!is_null($obj)){
					$obj->id = $row['PARAMETER_NAME'];
					McsParameters::cacheObject($obj);
					$objs[] = $obj;
				}
			}
			$dbh->commit();
			return $objs;
		}
		catch(Exception $e) {
			$dbh->rollBack();
			throw new Exception("La récuperation de la liste d'objets de type McsParameters a échouée",0,$e);
		}
	}

	public static function getCount( $search_params = array(),$options = array()){
		$dbh = SingletonPDO::getInstance();
		try{
			$dbh->beginTransaction();
			$objs = array();
			$sql = 'SELECT count(*) as count FROM `mcs_parameters`';
			$sql .= self::generateWhereClause($search_params);
			$sql .= self::generateOptionClause($options);
			$stmt = $dbh->prepare($sql);
			$array = array();
			$cpt = 0;
			foreach($search_params as $ind => $search_param){
				//ajouter un parametre au tableau
				if($search_param['operator'] === 'BETWEEN' && is_array($search_param['value']) && count($search_param['value']) == 2 ){
					$array[':'.$search_param['field'].$cpt.'_0'] = $search_param['value'][0];
					$array[':'.$search_param['field'].$cpt.'_1'] = $search_param['value'][1];
				}
				else if($search_param['operator'] === 'IN' && is_array($search_param['value']) && count($search_param['value']) > 0){
					$i = 0;
					foreach($search_param['value'] as $key => $val){
						$array[':'.$search_param['field'].$cpt.'_'.$i] = $val;
						$i++;
					}
					if($i == 0){
						throw new Exception("L'opérateur IN doit comporter au moins une valeur");
					}
				}
				else if ($search_param['operator'] === 'IS NULL' || $search_param['operator'] === 'IS NOT NULL'){
					continue;
				}
				else{
					$array[':'.$search_param['field'].$cpt] = $search_param['value'];
				}
				$cpt++;
			}
			$stmt->execute($array);
			$count = $stmt->fetch();
			$dbh->commit();
			return $count['count'];
		}
		catch(Exception $e) {
			$dbh->rollBack();
			throw new Exception("La récuperation de la liste d'objets de type McsParameters a échouée",0,$e);
		}
	}

	public static function deleteAll( $search_params = array()){
		$dbh = SingletonPDO::getInstance();
		try{
			$dbh->beginTransaction();
			$objs = array();
			$sql_delete = 'DELETE FROM `mcs_parameters`';
			$sql_select = 'SELECT PARAMETER_NAME FROM `mcs_parameters`';
			$sql_delete .= self::generateWhereClause($search_params);
			$sql_select .= self::generateWhereClause($search_params);
			$stmt_delete = $dbh->prepare($sql_delete);
			$stmt_select = $dbh->prepare($sql_select);
			$array = array();
			$cpt = 0;
			foreach($search_params as $ind => $search_param){
				//ajouter un parametre au tableau
				if($search_param['operator'] === 'BETWEEN' && is_array($search_param['value']) && count($search_param['value']) == 2 ){
					$array[':'.$search_param['field'].$cpt.'_0'] = $search_param['value'][0];
					$array[':'.$search_param['field'].$cpt.'_1'] = $search_param['value'][1];
				}
				else if($search_param['operator'] === 'IN' && is_array($search_param['value']) && count($search_param['value']) > 0){
					$i = 0;
					foreach($search_param['value'] as $key => $val){
						$array[':'.$search_param['field'].$cpt.'_'.$i] = $val;
						$i++;
					}
					if($i == 0){
						throw new Exception("L'opérateur IN doit comporter au moins une valeur");
					}
				}
				else if ($search_param['operator'] === 'IS NULL' || $search_param['operator'] === 'IS NOT NULL'){
					continue;
				}
				else{
					$array[':'.$search_param['field'].$cpt] = $search_param['value'];
				}
				$cpt++;
			}
			$var_select = $stmt_select->execute($array);
			$tab_to_delete_objects = $stmt_select->fetchAll();
			if(sizeof($tab_to_delete_objects) > 0){
				$var_delete = $stmt_delete->execute($array);
				foreach($tab_to_delete_objects as $ind => $row){
					$existing_object = McsParameters::getObjectFromCache($row['PARAMETER_NAME']);
					if(!is_null($existing_object)){
						$existing_object->id = null;
						McsParameters::removeObjectFromCache($row['PARAMETER_NAME']);
					}
				}
			}
			$dbh->commit();
		}
		catch(Exception $e) {
			$dbh->rollBack();
			throw new Exception("La suppression de la liste d'objets de type McsParameters a échouée",0,$e);
		}
	}

}